/*
#Copyright (c) 2013, Philippe Bordron <philippe.bordron@gmail.com>
#
# This file is part of SIPPER.
#
# DCC is free software: you can redistribute it and/or modify
# it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# DCC is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU LESSER GENERAL PUBLIC LICENSE for more details.
#
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE
# along with SIPPER.  If not, see <http://www.gnu.org/licenses/>
*/
package combi.wip.sipper.modeling.genomes;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.SortedSet;
import java.util.TreeSet;

import combi.wip.sipper.modeling.Protein;

public class LinearGenome<G extends Gene<E>, E extends Protein> extends Genome<G, E> {

	public LinearGenome(List<G> genesSequence) {
		super(genesSequence);
	}

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	public List<Gene<E>> smallestInducedIntervalOfGenes(Collection<G> genes) {
		List<Gene<E>> result = new ArrayList<Gene<E>>();
		SortedSet<Integer> ranks = new TreeSet<Integer>(this.getRanks(genes));
		if(!ranks.isEmpty())
		{
			result.addAll(this.subList(ranks.first(),ranks.last()+1));
		}
		ranks.clear();
		return result;
	}

	@Override
	public double sizeOfSmallestInducedIntervalOGenes(Collection<G> genes) {
		double result = Double.NaN;
		SortedSet<Integer> ranks = new TreeSet<Integer>(this.getRanks(genes));
		if(!ranks.isEmpty())
		{
			result = ranks.last() - ranks.first() + 1;
		}
		ranks.clear();
		return result;
	}

}
